import { ResPage } from '@/api/interface'
import { AnimalPlant } from './interface'
import { TBY } from '@/api/config/servicePort'
import http from '@/api'

export const pageAnimalPlant = (params: AnimalPlant.Query) => {
  return http.get<ResPage<AnimalPlant.Record>>(TBY + `/animal_plant/page`, params)
}

// 动植物详情
export const getAnimalPlantDetail = (id: number) => {
  return http.get<Partial<AnimalPlant.Form>>(TBY + `/animal_plant/get`, { id }, { loading: false })
}

// 新增或修改动植物
export const saveOrUpdateAnimalPlant = (params: Partial<AnimalPlant.Form>) => {
  return http.post(TBY + `/animal_plant/save_or_update`, params)
}

// 删除动植物
export const removeAnimalPlant = (id: number) => {
  return http.delete(TBY + `/animal_plant/delete`, { id })
}

// 动植物列表
export const listAnimalPlant = (params: AnimalPlant.Query) => {
  return http.get<AnimalPlant.Record[]>(TBY + `/animal_plant/list`, params)
}

// 概况可以选择的动植物下拉选数据
export const listUseOverview = () => {
  return http.get<AnimalPlant.Record[]>(TBY + `/animal_plant/use_overview_list`)
}

// 下拉选
export function options() {
  return http.get<OptionType[]>(TBY + '/animal_plant/options')
}

// 获取下拉框的内容，物种分类和物种
export function selectDataOption() {
  return http.get<OptionType[]>(TBY + '/animal_plant/cascader_list')
}

// 验证名称是否存在
export const chNameExist = (chName: string, id?: number) => {
  return http.get<boolean>(TBY + '/animal_plant/exist', { chName, id }, { loading: false })
}

// 物种下拉选
export const selectOptionList = (params: AnimalPlant.Query) => {
  return http.get<OptionType[]>(TBY + `/animal_plant/select_option`, params)
}
